package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerAddDTO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.entity.Customer;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李智勇
 * @data 2025/10/17 21:20
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @LogAnno
    @PutMapping
    public Result updata(@RequestBody Customer customer){
        customerService.updateById(customer);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }

    @LogAnno
    @PostMapping
    public Result add(@RequestBody CustomerAddDTO dto) {
        customerService.add(dto);
        return Result.success();
    }


    @GetMapping
    public Result list(CustomerDTO dto) {
        PageResult<CustomerDO> pageResult = customerService.customerList(dto);
        return Result.success(pageResult);
    }
}
